//字符串解码
class Solution {
public:
    string decodeString(string s) {
        vector<string> Sstack;
        Sstack.push_back("");
        //    Sstack.push_back("");
        // cout<<Sstack.size();
        vector<int> Istack;
        for (int i = 0; i < s.size(); i++) {
            if (s[i] >= 'a' && s[i] <= 'z') {
                Sstack.back() += s[i];
            } else if (s[i] == ']') {
                int n = Istack.back();
                string Stemp;
                while (n) {
                    Stemp += Sstack.back();
                    n--;
                }
                Sstack.pop_back();
                Istack.pop_back();
                Sstack.back() += Stemp;
            } else {
                int temp = 0;
                while (s[i] >= '0' && s[i] <= '9')
                    temp = 10 * temp + (s[i++] - '0');
                Istack.push_back(temp);
                Sstack.push_back("");
            }
            // for (auto& S : Sstack)
            // cout << S << " ";
            //  cout << endl;
        }
        return Sstack.back();
    }
};


//验证栈序列
class Solution {
public:
    bool validateStackSequences(vector<int>& pushed, vector<int>& popped) {
        vector<int> stack;
        int i = 0;
        for (auto& num : pushed) {
            stack.push_back(num);
            while (stack.size() && stack.back() == popped[i]) {
                stack.pop_back();
                i++;
            }
        }
        if (stack.empty())
            return true;
        return false;
    }
};